﻿package game 
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.TimerEvent;
	import flash.text.TextField;
	import flash.utils.Timer;
	import game.events.EventData;
	import game.exchangeddata.HashTable;
	/**
	 * ...
	 * @author Nguyen Thi Bich Phuong (Daisy)
	 */
	public class CountDownPanel extends MovieClip {		
		public var counterTf:TextField;
		public var statusBettingTf:TextField;
		
		public var second:int = 0;
		public var timer:Timer;
		
		public function CountDownPanel() {
			this.timer = new Timer(1000);
			this.counterTf.text = "0";
			//this.statusBettingTf.text = "STOP BETTING";
			this.statusBettingTf.text = "";
			this.timer.addEventListener(TimerEvent.TIMER, timerHandler);
		}
		
		public function initText(hashTableInfo:HashTable) {
			this.statusBettingTf.text = hashTableInfo.lookupString("INFOStopBetting");
		}
		
		/**
		 * @author Daisy
		 * @param	e
		 */
		private function timerHandler(e:TimerEvent):void {
			
			this.second--;
			//trace("timerHandler:" + this.second);
			this.counterTf.text = this.second.toString();
				if (this.second == 0) {
					this.timer.stop();
					//this.statusBettingTf.text = "STOP BETTING";
					this.statusBettingTf.text = GlobalVariables.langInfo.hashTable.lookupString("INFOStopBetting");
					dispatchEvent(new Event(EventData.COUNTDOWN_COMPLETE, true));
				}
				//Bamboo dispatchEvent to play sound 
				if (this.second <= 10 && this.second >0) {
					//trace("sound");
					dispatchEvent(new EventData(EventData.GET_SOUND_COUNT_DOWN, true));
				}
				
		}
		
		/**
		 * @author Daisy
		 * @param	pSecond
		 */
		public function startCountDown(pSecond:int):void {
			this.second = pSecond;
			this.counterTf.text = this.second.toString();
			//this.statusBettingTf.text = "BETTING NOW";
			this.statusBettingTf.text = GlobalVariables.langInfo.hashTable.lookupString("INFOStartBetting");
			this.timer.start();
		}
		/**
		 * @author	Bamboo
		 */
		public function stopCountDown():void {
			//trace("stopCountDown:");
			this.counterTf.text = "0";
			//this.statusBettingTf.text = "STOP BETTING";
			this.statusBettingTf.text = GlobalVariables.langInfo.hashTable.lookupString("INFOStopBetting");
			this.timer.stop();
		}
	}

}